//package com.pic.others.handler;
//
//import com.pic.common.autoconfigure.mq.RabbitMqHelper;
//import com.pic.common.constants.MqConstants;
//import com.pic.common.constants.RedisConstants;
//import com.pic.common.utils.R;
//import com.pic.others.domain.po.Bottle;
//import com.pic.others.domain.po.Notice;
//import com.pic.others.domain.po.Picture;
//import com.pic.others.domain.po.PictureDescribe;
//import com.pic.others.mapper.NoticeMapper;
//import com.pic.others.mapper.PictureDescribeMapper;
//import com.pic.others.mapper.PictureMapper;
//import com.pic.others.mapper.UserMapper;
//import com.pic.others.mq.message.EmailMessage;
//import com.pic.others.service.impl.BottleServiceImpl;
//import com.pic.others.service.impl.PictureDescribeServiceImpl;
//import com.pic.others.service.impl.PictureServiceImpl;
//import com.xxl.job.core.handler.annotation.XxlJob;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.checkerframework.checker.units.qual.N;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import static com.pic.others.constants.user.UserConstants.USER_VERIFY_CODE_KEY_REGISTER;
//
//@Slf4j
//@RequiredArgsConstructor
//@Component
//public class AutoBottleHandler {
//    private final UserMapper userMapper;
//    private final PictureMapper pictureMapper;
//    private final PictureServiceImpl pictureService;
//    private final PictureDescribeMapper pictureDescribeMapper;
//    private final PictureDescribeServiceImpl pictureDescribeService;
//    private final StringRedisTemplate redisTemplate;
//    private final RabbitMqHelper mqHelper;
//    private final BottleServiceImpl bottleService;
//    private final NoticeMapper noticeMapper;
//
//        //自动 隔一定时间内，开始计算用户的情绪，然后开始推荐漂流瓶关心
//@XxlJob("inTimeDeleteNote")
//    public R<Bottle> inTimeDeleteNote(){
//    List<Long> allUserId = userMapper.getAllUserId();
//    for(Long userId:allUserId){
//        int totalPictureNumber=pictureService.lambdaQuery().eq(Picture::getUserId,userId).count();
//        int badMoodNumber = pictureDescribeService
//                .lambdaQuery()
//                .eq(PictureDescribe::getUserId, userId)  // 等于 userId 的条件
//                .and(lq -> lq.like(PictureDescribe::getMood, "sad")  // mood 包含 "sad" 的条件
//                        .or()   // 逻辑 OR 连接
//                        .like(PictureDescribe::getMood, "happy"))  // mood 包含 "happy" 的条件
//                .count();  // 执行查询并返回满足条件的记录数
//
//
//        double score=totalPictureNumber/badMoodNumber;
//        if(score>=0.76){
//            String randomBottleId = (String) redisTemplate.opsForZSet().randomMember(RedisConstants.bottle.BOTTLE_ID);
//                    if(randomBottleId==null){
//                       continue;
//        }
//            //
//            Bottle bottle = bottleService.getById(randomBottleId);
//            Notice notice=new Notice(1,Long.valueOf(randomBottleId),userId,bottle.getBottleContent());
//            noticeMapper.insert(notice);
//            mqHelper.send(
//                    MqConstants.Exchange.BOTTLE_EXCHANGE,
//                    MqConstants.Key.BOTTLE_HANDLER,
//                    randomBottleId
//            );
//            log.info("bottle:{}",bottle);
//        }
//    }
//
//    return null;
//    }
//
//}
////    @Override
////    public R<String> getBottle() {
////        // 从Zset中随机获取漂流瓶的ID
////        String randomBottleId = (String) redisTemplate.opsForZSet().randomMember(RedisConstants.bottle.BOTTLE_ID);
////        if(randomBottleId==null){
////            return R.success("没有漂流瓶了，下次再来吧！");
////        }
////
////        Bottle bottle = getById(randomBottleId);
////        //开rabbitmq
//////        mqHelper.send(
//////                MqConstants.Exchange.SMS_EXCHANGE,
//////                MqConstants.Key.SMS_MESSAGE,
//////                EmailMessage.of(email,USER_VERIFY_CODE_KEY_REGISTER)
//////        );
////        mqHelper.send(
////                MqConstants.Exchange.BOTTLE_EXCHANGE,
////                MqConstants.Key.BOTTLE_HANDLER,
////                randomBottleId
////        );
////        return R.success(bottle.getBottleContent());
////    }